﻿var _lang = {
		zh1: {
			skip_btn:"<img src='/game-assets/img/close-btn.png'>",
			home_top:"<img src='/game-assets/img/home-top.png'>",
			home_content:"<img src='/game-assets/img/home-content.png' >",
			title: "大家都来找第字",
			help_txt: "找出所有色块里颜色不同的一个",
			score: "得分：",
			btn_pause: "暂停",
			btn_start: "开始游戏",
			btn_reTry: "继续闯关",
			btn_prize:"我的奖品",
			btn_more_game: "找第秘籍",
			game_pause: "游戏暂停",
			btn_resume: "继续闯关",
			loading: "加载中...",
			lv_txt:["</game-assets/img/less20-score1.png"],
//			lv_txt: ["瞎子", "色盲", "色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色"],
			share_txt1: "我闯过",
			share_txt2: "关，击败",
			share_txt3: "%的人，我是【",
			share_txt4: "】，不服来战！",
			desc: "找出所有色块中颜色不同的一块。分享朋友圈，找到身边的色魔"
		},
		zh: {
			skip_btn:"<img src='/game-assets/img/close-btn.png'>",
			home_top:"<img src='/game-assets/img/home-top.png'>",
			home_content:"<img src='/game-assets/img/home-content.png' >",
			title: "大家都来找第字",
			help_txt: "在众多<span style='font-size:240%'>笫</span>字中找到唯一的<span style='font-size:240%'>第</span>字",
			score: "过关：",
			btn_pause: "暂停",
			btn_start: "开始游戏",
			btn_reTry: "继续闯关",
			btn_prize:"我的奖品",
			btn_more_game: "找第秘籍",
			game_pause: "游戏暂停",
			btn_resume: "继续闯关",
			loading: "加载中...",
			lv_txt:["/game-assets/img/less20-score1.png","/game-assets/img/than20-score1.png","/game-assets/img/than60-score1.png"],
//			lv_txt: ["色郎", "色狼", "色鬼", "色魔", "超级色魔", "变态色魔", "孤独求色", ],
			share_txt1: "【找第子】我在",
			share_txt2: "只笫子中找到",
			share_txt3: "个第子，我是【",
			share_txt4: "】，不服来战！",
			desc: "找出所有'笫'字中的'第'字。分享朋友圈，找到身边的色魔"
		},
		en: {
			title: "How strong is your eyesight",
			help_txt: "Find the box with the different colour",
			score: "Score：",
			btn_pause: "Pause",
			btn_start: "Start",
			btn_reTry: "Again",
			btn_more_game: "More games",
			game_pause: "Pause",
			btn_resume: "Continues",
			loading: "loading...",
			lv_txt: ["Blind", "Very weak", "Weak", "Just so so", "Not bad", "Nice one", "Great", "Amazing", "Insane"],
			share_txt1: "I passed ",
			share_txt2: "stages and defeated ",
			share_txt3: "% people. I am ",
			share_txt4: ", come to challenge me if you dare！",
			desc: "Find the box with the different colour, share it to your friends!"
		}
	},

	_config = {
		lang: "zh",
		color: {
			allTime:60,
			addTime: 0,
			lvMap: [2, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9]
		},
		pic: {
			isOpen: !1,
			allTime: 5,
			addTime: 0,
			lvMap: [2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8]
		}
	},
	shareData = {
//		imgUrl: "http://resource5.duopao.com/duopao/games1/icon/mei2.png",
//		timeLineLink: "http://uc.duopao.com/uc/wxlogin?url=http://www.duopao.com/games/play/g20140806172647919491",
		tTitle: _lang[_config.lang].title + "?",
		tContent: _lang[_config.lang].desc,
		totalZizi: 0
	};
! function() {
	var a = _lang[_config.lang],
		b = $("#tpl").html(),
		c = _.template(b, a);
	$("body").html(c)
//	,$("title").html(a.title)
}
(),
function() {
	var a = $("#box"),
		b = {
			lv: $("#room .lv em"),// 分数
			time: $("#room .time"),//倒计时时间
			start: $("#dialog .btn-restart"), //游戏开始
			back: $("#dialog .btn-back"), 
			share: $("#dialog .btn-share"),
			pause: $("#room .btn-pause"),//暂停
			resume: $("#dialog .btn-resume"), //暂停之后，继续游戏
			dialog: $("#dialog"),//弹框
			d_content: $("#dialog .content"),//弹框的内容
			d_pause: $("#dialog .pause"), //游戏暂停时弹框
			d_gameover: $("#dialog .gameover") //游戏结束时的弹框
		},
		c = {
			init: function(a, b, c) {
				this.type = a, this.api = API[a], this.config = _config[a], this.reset(), this.parent = c, this.el = b, this.renderUI(), this.inited || this.initEvent(), this.inited = !0, this.start()
			},
			renderUI: function() {
				var b = 90 == window.orientation || -90 == window.orientation,
					c = b ? window.innerHeight : window.innerWidth;
				c -= 20, c = Math.min(c, 500), a.width(c).height(c), this.el.show()
			},
			initEvent: function() {
				var d = "ontouchstart" in document.documentElement ? "touchend" : "click",
					e = this;
				$(window).resize(function() {
					c.renderUI()
				}), a.on(d, "span", function() {  //点击dialog中span标签
					var a = $(this).data("type"); //type指什么
					"a" == a && e.nextLv.call(e)
				}), b.pause.on(d, _.bind(this.pause, this)), b.resume.on(d, _.bind(this.resume, this)), b.start.on(d, _.bind(this.start, this)), b.back.on(d, _.bind(this.back, this)), b.share.on(d, _.bind(this.share, this))
			},
			start: function() {
				if (this.lv == -1)// 开始游戏之前分数是-1
					shareData.totalZizi = 0; //分享笫字的个数
					
				this.time > 5 && b.time.removeClass("danger"),  //倒计时大于5秒是移除danger  class属性
				b.dialog.hide(), 
				this._pause = !1,
				this.lv = "undefined" != typeof this.lv ? this.lv + 1 : 0,  //分数为字符串时返回0
				this.lvMap = this.config.lvMap[this.lv] || _.last(this.config.lvMap), 
				this.renderMap(), 
				this.renderInfo()
				this.timer || (this.timer = setInterval(_.bind(this.tick, this), 1e3));
			},
			share: function() {},
			resume: function() {
				b.dialog.hide(), 
				this._pause = !1
			},
			pause: function() {
				this._pause = !0, 
				b.d_content.hide(), 
				b.d_pause.show(), 
				b.dialog.show()
			},
			tick: function() {
				return this._pause ? void 0 : (this.time--, this.time < 6 && b.time.addClass("danger"), this.time < 0 ? void this.gameOver() : void b.time.text(parseInt(this.time)))
			},
			renderMap: function() {
				console.log(this._pause)
				if (!this._pause) { 
					var b = this.lvMap * this.lvMap,
						c = "",
						d = "lv" + this.lvMap;
					_(b).times(function() {c += "<span></span>"}), 
					a.attr("class", d).html(c),
//					this.lv = 30, //测试管的关数
					this.api.render(this.lvMap, this.lv)
				}
			},
			renderInfo: function() {
				b.lv.text(this.lv + 1)
			},
			gameOver: function() {
				var Rankstr = "";

              /*  $.post('/finddi/findfinum?cishu='+this.lv,
                   /!* function (data) {
                       console.log("succeshdfhasdjkfhiadh-------------------------------------------------------------------"+data.pri);

                    }*!/
                   );*/




                $.ajax('/finddi/findfinum', {
                    async : false,
                    data: {
                        cishu:this.lv
                    },
                    type: 'post',
                    dataType: 'json',
                   /* success: function(data) {
               			 console.log("看阿奎那看你看看那看你看看那看gdfgadnfkgnkdfngkdfkgjsdf那看那看那看看你"+data);
            		},
					error:function () {
						console.log("shibaibaibaisdbfhasdfhasdhfhasdhfjhasdjfhjkahsdjgfhajsdhfgahsdkjghajdshfgahdsjfasd")
                    }*/

                });

				//document.title = window.shareData.tTitle = "我一共发现了" + this.lv + "个第字" + Rankstr + ",有本事就来挑战！"
				try {
					WeixinJSBridge.call("showOptionMenu")
				} catch (c) {}
				var d = this.api.getGameOverText(this.lv); //游戏结束 获取分数
				this.lastLv = this.lv, 
				this.lastGameTxt = d.txt, //游戏结束获取的文字
				console.log(d.txt)
				this.lastGamePercent = d.percent, //
				b.d_content.hide(), 
				b.d_gameover.show().find(".gameover img.alert-img").attr("src",this.lastGameTxt),
				console.log($(".gameover img.alert-img").attr("src",this.lastGameTxt)),
				console.log($(".gameover").html()),
//				b.d_gameover.show().find("h3").text(this.lastGameTxt), //游戏结束时  显示内容
				a.find("span").fadeOut(1500, function() {
					b.dialog.show()
				}), 
				this._pause = !0, 
				_hmt.push(["_trackEvent", "score", "score_" + (this.lv + 1)]), 
				this.reset()
			},
			reset: function() {
				this.time = this.config.allTime,
				this.lv = -1
			},
			nextLv: function() {
				this.time += this.config.addTime, 
				b.time.text(parseInt(this.time)), 
				this._pause || this.start()
			},
			back: function() {
				this._pause = !0, this.el.hide(), b.dialog.hide(), this.parent.render()
			}
		};
	window.Game = c
}
(),
function(a) {
	var b = {
			index: $("#index"),
			room: $("#room"),
			loading: $("#loading"),
			dialog: $("#dialog"),
			play: $(".play-btn"),
			btn_boyaa: $(".btn-boyaa"),
			banner: $(".banner"),
			boyaa_logo: $(".boyaa-logo")
		},
		c = window.navigator.userAgent.toLowerCase(),
		d = /android/i.test(c),
		e = /iphone|ipad|ipod/i.test(c),
		f = {
			init: function() {
				this.initEvent(), this.loading(), /android/i.test(c) ? (b.banner.attr("href", "").data("type", "android").find("img").attr("src", "assets/img/banner.android.jpg"), b.banner.show()) : /iphone|ipad|ipod/i.test(c) && (b.banner.attr("href", "http://www.17w67.com/").data("type", "ios").find("img").attr("src", "assets/img/banner.ios.jpg"), b.banner.show())
			},
			loading: function() {
				function a() {
					d++, d == c && f.render()
				}
				if (_config.pic.isOpen)
					for (var b = ["assets/img/1.png", "assets/img/2.png", "assets/img/3.png", "assets/img/4.png", "assets/img/5.png", "assets/img/6.png", "assets/img/7.png", "assets/img/8.png", "assets/img/9.png", "assets/img/10.png", "assets/img/11.png", "assets/img/12.png", "assets/img/13.png", "assets/img/14.png", "assets/img/15.png", "assets/img/16.png", "assets/img/17.png", "assets/img/18.png"], c = b.length, d = 0, e = 0; c > e; e++) {
						var g = new Image;
						g.onload = a, g.src = b[e]
					}
				else
					f.render();
				var h = _lang[_config.lang];
			},
			render: function() {
				setTimeout(function() {
					b.loading.hide(), b.index.show()
				}, 1e3)
			},
			initEvent: function() {
				var a = "ontouchstart" in document.documentElement ? "touchstart" : "click",
					c = this;
				b.play.on(a, function() {
					var a = $(this).data("type") || "color";
					b.index.hide(), Game.init(a, b.room, c)
				}), b.btn_boyaa.on(a, function() {
					_hmt.push(["_trackEvent", "button", "more_game"])
				}), b.boyaa_logo.on(a, function() {
					_hmt.push(["_trackEvent", "button", "boyaa_logo"])
				}), b.banner.on(a, function() {
					var a = $(this).data("t") || "",
						b = d ? "android" : e ? "ios" : "other_os";
					_hmt.push(["_trackEvent", "banner", b + "_" + a])
				})
			}
		};
	f.init(), a.API = {}
}
(window),
function() {
	var a = $("#box"),
		b = "span",
		c = $("#help p"),
		d = $("#help_color"),
		e = {
			lvT: _lang[_config.lang].lv_txt, //判断的等级显示
			render: function(e, f) {
				this.lv = f, c.hide(), d.show();
				var g = _config.color.lvMap[f] || _.last(_config.color.lvMap);
				this.d = 15 * Math.max(9 - g, 1), this.d = f > 20 ? 10 : this.d, this.d = f > 40 ? 8 : this.d, this.d = f > 50 ? 5 : this.d;
				var h = Math.floor(Math.random() * e * e * 2),
					i = this.getColor(255 - this.d),
					j = this.getLvColor(i[0]);
				shareData.totalZizi += e * e;
				var size = a.find(b).height() * 0.96;
				a.find(b).css("background-color", i[1]).data("type", "b").html('<span style="padding:0px;border:0;font-size:' + size + 'px;line-height:' + size + 'px;width:100%;height:100%" >笫</span>'), a.find(b).eq(h).css("background-color", i[1]).data("type", "a").html('<span style="padding:0px;border:0;font-size:' + size + 'px;line-height:' + size + 'px;width:100%;height:100%" >第</span>')
			},
			getColor: function(a) {
				var b = [Math.round(Math.random() * a), Math.round(Math.random() * a), Math.round(Math.random() * a)],
					c = "rgb(" + b.join(",") + ")";
				return [b, c]
			},
			getLvColor: function(a) {
				var b = this.d,
					c = _.map(a, function(a) {
						return a + b + 10
					}),
					d = "rgb(" + c.join(",") + ")";
				return [c, d]
			},
			//控制识别等级
			getGameOverText: function(a) {
				//为了测试回头要删掉
				//var a = 70;

				var b = 20 >a ? 0 : Math.floor(a / 10),
					c = this.lvT[b] || _.last(this.lvT),
//					d = c + "lv" + (a + 1), //需要改变的内容
					d = c,
					e = a;
					console.log(this.lvT)
					console.log(a)
					console.log(b)
					console.log(_.last(this.lvT))
					console.log(c)
					console.log(Math.ceil((a - 20) / 10))
					if(b <= 1){
						$(".less20-score").show();
						$(".than20-score").hide();
						$(".than60-score").hide();
						$(".alert-content").css({"margin-top":"0","width":"100%","height":"100%","top":"0","left":"0","margin-left":"0"});
					}else if(b == 2|| b == 3|| b == 4 || b == 5){
						$(".gameover .alert-img").css({"width":"100%","margin-top":"0"});
						$(".less20-score").hide();
						$(".than20-score").css("display","block");
						$(".than60-score").hide();
					}else if(b >= 6){
						$(".gameover .alert-img").css({"width":"100%","margin-top":"0"});
						$(".less20-score").hide();
						$(".than20-score").css("display","none");
                        $.ajax({
                            async : false,
                            url:"/finddi/tests",
                            type:"post",
                            data:{
                                a:a
                            },
                            success: function(data) {
                                var sas = data.ss;
                                var bian = data.bian;
								$(".yuan").text(sas);
								$(".bian").text(bian);

                            },
                            error: function() {
                                console.log("error")
                            }
                        });
						$(".than60-score").show();
					}
					return e = 20 > e ? a : 60 > a ? .05 * (a - 50) + 98.5 : 100,
					console.log(a),
					e = ("" + e).length > 5 ? e.toFixed(2) : e,
					{
						txt:d,
						percent:e
					}
					
//				return e = 20 > e ? 2 * a : 30 > a ? 3 * (a - 20) + 40 : 40 > a ? 1.5 * (a - 30) + 70 : 50 > a ? 1.35 * (a - 40) + 85 : 60 > a ? .05 * (a - 50) + 98.5 : 70 > a ? .02 * (a - 60) + 99 : 80 > a ? .02 * (a - 70) + 99.2 : 90 > a ? .02 * (a - 80) + 99.4 : 100 > a ? .02 * (a - 90) + 99.6 : 110 > a ? .02 * (a - 100) + 99.8 : 100, e = ("" + e).length > 5 ? e.toFixed(2) : e, {
//					txt: d,
//					percent: e
//				}
			}
		};
	API.color = e
}
();